<?php

namespace Drinkiit\UtilisateurBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Drinkiit\BlogBundle\Entity\Operations;
use Drinkiit\BlogBundle\Entity\Commande;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class UtilisateurApp extends BaseUser
{
    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\generatedValue(strategy="AUTO")
    */
    protected $id;
    
    /**
    * @ORM\Column(type="string", length=50, nullable=true)
    */
    private $nom;

    /**
    * @ORM\Column(type="string", length=50, nullable=true)
    */
    private $prenom;
    
     /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $solde;
    
     /**
     * @ORM\oneToMany(targetEntity="Drinkiit\BlogBundle\Entity\Commande", mappedBy="utilisateur_commande")
     */
    private $commande;
    
     /**
     * @ORM\oneToMany(targetEntity="Drinkiit\BlogBundle\Entity\Operations", mappedBy="operation_utilisateur")
     */
    private $operation;

    public function __construct()
    {
        parent::__construct();
        
        $this->commande = new \Doctrine\Common\Collections\ArrayCollection();
		$this->operation = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nom
     *
     * @param string $nom
     */
    public function setNom($nom)
    {
        $this->nom = $nom;
    }

    /**
     * Get nom
     *
     * @return string 
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set prenom
     *
     * @param string $prenom
     */
    public function setPrenom($prenom)
    {
        $this->prenom = $prenom;
    }

    /**
     * Get prenom
     *
     * @return string 
     */
    public function getPrenom()
    {
        return $this->prenom;
    }

    /**
     * Set solde
     *
     * @param integer $solde
     */
    public function setSolde($solde)
    {
        $this->solde = $solde;
    }

    /**
     * Get solde
     *
     * @return integer 
     */
    public function getSolde()
    {
		$solde = 0 ;
		
		$liste_operations = $this->getOperation() ;
		foreach ( $liste_operations as $key => $operation) {
			$solde += $operation->getOperation() ;
		}
		
		foreach ($this->getCommande() as $key => $commande) {
			
			if ( !$commande->getEstMenu() and $commande->getValidee() )
			{
				$solde -= $commande->getPrix() ;
			}
			
		}
		
        return $solde;
    }

    /**
     * Add commande
     *
     * @param Drinkiit\BlogBundle\Entity\Commande $commande
     */
    public function addCommande(\Drinkiit\BlogBundle\Entity\Commande $commande)
    {
        $this->commande[] = $commande;
    }

    /**
     * Get commande
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getCommande()
    {
        return $this->commande;
    }

    /**
     * Add operation
     *
     * @param Drinkiit\BlogBundle\Entity\Operations $operation
     */
    public function addOperations(\Drinkiit\BlogBundle\Entity\Operations $operation)
    {
        $this->operation[] = $operation;
    }

    /**
     * Get operation
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getOperation()
    {
        return $this->operation;
    }
}
